//
//  FeedbackDetailViewController.m
//  CPICApp
//
//  Created by lizhiwei on 13-3-19.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "FeedbackDetailViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "RCAlertViewUtil.h"

@interface FeedbackDetailViewController ()

@end

@implementation FeedbackDetailViewController
@synthesize FeedbackContent;
@synthesize FeedbackDate;
@synthesize FeedbackType;
@synthesize feedback;
@synthesize FeedbackResult;
@synthesize FeedbackStatus;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title=@"历史意见反馈详情";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"历史意见反馈详情");
        self.view.backgroundColor=[UIColor whiteColor];
        //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"历史意见反馈详情");
        self.view.backgroundColor=[UIColor whiteColor];
        //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"历史意见反馈详情");
        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    self.FeedbackDate = [self.feedback objectForKey:@"feedbackdate"];
    self.FeedbackType=[self.feedback objectForKey:@"opiniontype"];
    self.FeedbackContent=[self.feedback objectForKey:@"opinioncontent"];
    NSString *strStatus=[[NSString alloc]initWithFormat:@"%@",[self.feedback objectForKey:@"dealstatus"]];
    NSString *strResult;
    if ([self.feedback objectForKey:@"dealcontent"]) {
        strResult=[[NSString alloc]initWithFormat:@"%@",[self.feedback objectForKey:@"dealcontent"]];
    }
    else
    {
        strResult=@"";
    }
    
    if ([strStatus isEqualToString:@"1"]) {
        self.FeedbackStatus=@"待处理";
    }
    else if([strStatus isEqualToString:@"2"])
    {
        self.FeedbackStatus=@"处理中";
    }
    else if([strStatus isEqualToString:@"3"])
    {
        self.FeedbackStatus=@"已处理";
    }
    self.FeedbackResult=strResult;
    [strStatus release];
    [strResult release];
    
    NSLog(@"---------%@",self.FeedbackType);
    NSLog(@"---------%@",self.FeedbackDate);
    NSLog(@"---------%@",self.FeedbackContent);
    
    self.view.backgroundColor=[UIColor whiteColor];
    UILabel * lbFeedbackType = [[UILabel alloc]initWithFrame:CGRectMake(5, 60, 160, 20)];
    lbFeedbackType.text = @"意见反馈类型:";
    [self.view addSubview:lbFeedbackType];
    [lbFeedbackType release];
    
    UILabel * FeedbackTypeValue = [[UILabel alloc]initWithFrame:CGRectMake(140, 60, 150, 20)];
    FeedbackTypeValue.text = self.FeedbackType;
    [self.view addSubview:FeedbackTypeValue];
    [FeedbackTypeValue release];
    
    UILabel * lbFeedbackDate = [[UILabel alloc]initWithFrame:CGRectMake(5, 90, 160, 20)];
    lbFeedbackDate.text = @"意见反馈时间:";
    [self.view addSubview:lbFeedbackDate];
    [lbFeedbackDate release];
    
    UILabel * FeedbackDateValue = [[UILabel alloc]initWithFrame:CGRectMake(140, 90, 170, 20)];
    FeedbackDateValue.text = self.FeedbackDate;
    [self.view addSubview:FeedbackDateValue];
    [FeedbackDateValue release];
    
    UILabel * lbFeedbackContent = [[UILabel alloc]initWithFrame:CGRectMake(5, 120, 160, 20)];
    lbFeedbackContent.text = @"意见反馈内容:";
    [self.view addSubview:lbFeedbackContent];
    [lbFeedbackContent release];
    
    UITextView * FeedbackContentValue = [[UITextView alloc]initWithFrame:CGRectMake(18, 143, 280, 80)];
    FeedbackContentValue.text = self.FeedbackContent;
    FeedbackContentValue.font = [UIFont systemFontOfSize:16.0];
    FeedbackContentValue.layer.borderWidth =0.0;
    FeedbackContentValue.editable = NO;
    FeedbackContentValue.layer.borderColor = [UIColor grayColor].CGColor;
    FeedbackContentValue.layer.borderWidth =1.0;
    FeedbackContentValue.layer.cornerRadius =5.0;
    [self.view addSubview:FeedbackContentValue];
    [FeedbackContentValue release];
    
    UILabel * lbFeedbackStatusTag = [[UILabel alloc]initWithFrame:CGRectMake(5, 230, 160, 20)];
    lbFeedbackStatusTag.text = @"意见处理状态:";
    [self.view addSubview:lbFeedbackStatusTag];
    [lbFeedbackStatusTag release];
    
    UILabel * lbFeedbackStatus = [[UILabel alloc]initWithFrame:CGRectMake(140, 230, 160, 20)];
    lbFeedbackStatus.text = self.FeedbackStatus;
    [self.view addSubview:lbFeedbackStatus];
    [lbFeedbackStatus release];
    
    UILabel * lbFeedbackResultTag = [[UILabel alloc]initWithFrame:CGRectMake(5, 260, 160, 20)];
    lbFeedbackResultTag.text = @"意见处理结果:";
    [self.view addSubview:lbFeedbackResultTag];
    [lbFeedbackResultTag release];
    
    
    UITextView * txvFeedbackResult = [[UITextView alloc]initWithFrame:CGRectMake(18, 285, 280, 100)];
    txvFeedbackResult.text = self.FeedbackResult;
    txvFeedbackResult.font = [UIFont systemFontOfSize:16.0];
    txvFeedbackResult.layer.borderWidth =0.0;
    txvFeedbackResult.editable = NO;
    txvFeedbackResult.layer.borderColor = [UIColor grayColor].CGColor;
    txvFeedbackResult.layer.borderWidth =1.0;
    txvFeedbackResult.layer.cornerRadius =5.0;
    [self.view addSubview:txvFeedbackResult];
    [txvFeedbackResult release];
}

-(id)initView:(NSMutableDictionary *)Feedback
{
    self.feedback=Feedback;
    
    self = [super init];
    
    return self;
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    //[FeedbackDate release];
    //[FeedbackContent release];
    //[FeedbackType release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
